package com.instwall.callnumserver.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;

import androidx.annotation.Nullable;

import com.instwall.callbase.MConfig;
import com.instwall.callbase.tool.LogUtil;
import com.instwall.callnumlistener.CallNumNotification;
import com.instwall.callnumserver.ICallNumAidlInterface;
import com.instwall.callnumserver.ICallNumListener;


public class CallNumService extends Service {


    private ICallNumAidlInterface.Stub iBinder = new ICallNumAidlInterface.Stub() {
        @Override
        public void setOnNewCallListener(ICallNumListener listener) throws RemoteException {
            CallNumNotification.getCallNumNotification().addClientClientListener(listener);
        }

        @Override
        public void unsetOnNewCallListener(ICallNumListener listener) throws RemoteException {
            CallNumNotification.getCallNumNotification().removeClientListener(listener);
        }
    };

    @Override
    public void onCreate() {
        super.onCreate();
        LogUtil.LogI(MConfig.TAG, "[CallNumService][onCreate()]");
        mockLocalNotification();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        LogUtil.LogI(MConfig.TAG, "[CallNumService][onBind()]");
        return iBinder;
    }

    @Override
    public void onStart(Intent intent, int startId) {
        LogUtil.LogI(MConfig.TAG, "[CallNumService][onStart()]");
        super.onStart(intent, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /**
     * 跨进程通信
     * 1) 简单方式 广播 (此出不做演示)
     * 2) AIDL
     */
    private void mockLocalNotification() {
//        Timer timer = new Timer();
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                CallNumNotification.getCallNumNotification().notificationClient("Send Data From CallNumService");
//            }
//        }, 1000, 1000);
    }

}
